package com.winit.openapi.erp.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.winit.erp.spi.transportway.TransportWayService;
import com.winit.erp.spi.transportway.command.TransportWayCommand;
import com.winit.erp.spi.transportway.vo.TransportWay;
import com.winit.openapi.constants.ErrorCode;
import com.winit.openapi.controller.BaseController;
import com.winit.openapi.exception.ApiException;
import com.winit.openapi.model.RequestMsg;
import com.winit.openapi.model.ResponseMsg;

@Controller
@RequestMapping(value = "/transportWay")
public class TransportWayController extends BaseController {

    @Resource
    private TransportWayService transportWayService;

    @RequestMapping(value = "/queryTransportWayList")
    public String queryTransportWay(@ModelAttribute RequestMsg requestMsg, @ModelAttribute ResponseMsg responseMsg) {
        Object obj = requestMsg.getData();

        if (obj instanceof JSONObject) {
            JSONObject json = (JSONObject) obj;
            TransportWayCommand command = new TransportWayCommand();
            command.setWarehouseId(json.getLong("warehouseId"));
            command.setPostCode(json.getString("postCode"));
            command.setIsBattery(json.getString("isBattery"));
            command.setAdLanguage(requestMsg.getLanguage());
            List<TransportWay> lstTransportWay = transportWayService.queryTransportWay(command);
            responseMsg.setData(lstTransportWay);
        } else {
            throw new ApiException(ErrorCode.FIELD_TYPE_ERROR, "data");
        }
        return SUCCESS;
    }

}
